"""
Created on 28-Oct-2009

@author: dexen
"""

#===============================================================================
# SLAVE STATES
#===============================================================================
IDLE = "IDLE"
CRASHED = "CRASHED"
EXECUTING = "EXECUTING"

#===============================================================================
# MASTER STATES
#===============================================================================
RUNNING = "RUNNING"
PAUSED = "PAUSED"
STOPPED = "STOPPED"

#===============================================================================
# EXECUTION STATES
#===============================================================================
FAILED = "FAILED"
SUCCEDED = "SUCCEDED"

class ExecInfo(object):
    def __init__(self, task_name):
        self.task_name = task_name
        self.state = SUCCEDED
        self.exec_time = None
        
    def set_exec_time(self, exec_time):
        self.exec_time = exec_time

    def crashed(self):
        self.state = FAILED
        

class MasterInfo(object):
    def __init__(self, name):
        self.name = name
        self.state = RUNNING
        self._can_schedule = False
        
    def can_schedule(self, flag=None):
        if flag == None:
            return self._can_schedule
        self._can_schedule = flag
    
    def crashed(self):
        """
        To be called by master proxy
        """
        self.state = CRASHED
        print self.name, "is crashed!!!!!!!!!!!!!!"
        
    def is_crashed(self):
        return self.state == CRASHED
        
    def is_running(self):
        return self.state == RUNNING


class SlaveInfo(object):
    def __init__(self, name):
        self.name = name
        self.state = IDLE
        self.exec_info = None
        
    def crashed(self):
        self.state = CRASHED

    def is_crashed(self):
        return self.state == CRASHED
    
    def executing(self):
        self.state = EXECUTING

    def is_executing(self):
        return self.state == EXECUTING
    
    def idle(self):
        self.state = IDLE

    def is_idle(self):
        return self.state == IDLE
        

    

